package com.zhangyang;

import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created by ASUS on 2017/10/13.
 * 通过内存映射文件: 通过内存的数组来完成
 */
public class MapperBuffer {

    static int start=0;
    static int size=1024;
    /**
     * 主函数
     * @param args
     */
    public static void main(String args[]) throws Exception {
        RandomAccessFile randomAccessFile=new RandomAccessFile("D:\\gupao\\txt\\directBuffer.txt","rw");
        FileChannel fileChannel=randomAccessFile.getChannel();

        MappedByteBuffer mappedByteBuffer=fileChannel.map(FileChannel.MapMode.READ_WRITE,start,size);
        mappedByteBuffer.put(10,(byte)100);
        mappedByteBuffer.put(100,(byte)200);

    }
}
